//
//  ZJNetworkingManager.m
//  ZhuJianBuApp
//
//  Created by Mag1cPanda on 2017/2/6.
//  Copyright © 2017年 Mag1cPanda. All rights reserved.
//

#import "ZJNetworkingManager.h"
#import "AFNetworking.h"

@implementation ZJNetworkingManager
//#pragma mark - Special
//+(void)POST:(NSString *)serviceIP serviceName:(NSString *)serviceName params:(NSMutableDictionary *)params success:(ZJResponseSuccess)success fail:(ZJResponseFail)fail
//{
//    //拼接URL
//    NSString *url = [NSString stringWithFormat:@"%@/%@/query",serviceIP,serviceName];
//    NSLog(@"请求的完整链接 -> %@",url);
//
//    AFHTTPSessionManager *manager = [ZJNetworkingManager managerWithBaseURL:nil sessionConfiguration:NO];
//
//    // 设置超时时间
////    manager.requestSerializer.timeoutInterval = 10.f;
//
//    [manager POST:url parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//
//        id dic = [ZJNetworkingManager responseConfiguration:responseObject];
//
//        success(task,dic);
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        fail(task,error);
//    }];
//}
//
//#pragma mark - Universal
//+(void)GET:(NSString *)url params:(NSDictionary *)params
//   success:(ZJResponseSuccess)success fail:(ZJResponseFail)fail{
//
//    AFHTTPSessionManager *manager = [ZJNetworkingManager managerWithBaseURL:nil sessionConfiguration:NO];
//    [manager GET:url parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//
//        id dic = [ZJNetworkingManager responseConfiguration:responseObject];
//
//        success(task,dic);
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        fail(task,error);
//    }];
//}
//
//+(void)GET:(NSString *)url baseURL:(NSString *)baseUrl params:(NSDictionary *)params
//   success:(ZJResponseSuccess)success fail:(ZJResponseFail)fail{
//
//    AFHTTPSessionManager *manager = [ZJNetworkingManager managerWithBaseURL:baseUrl sessionConfiguration:NO];
//    [manager GET:url parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
//
//    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//
//
//        id dic = [ZJNetworkingManager responseConfiguration:responseObject];
//
//        success(task,dic);
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        fail(task,error);
//    }];
//
//}
//
//+(void)POST:(NSString *)url params:(NSDictionary *)params
//    success:(ZJResponseSuccess)success fail:(ZJResponseFail)fail{
//
//    AFHTTPSessionManager *manager = [ZJNetworkingManager managerWithBaseURL:nil sessionConfiguration:NO];
//
//    [manager POST:url parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//
//        id dic = [ZJNetworkingManager responseConfiguration:responseObject];
//
//        success(task,dic);
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        fail(task,error);
//    }];
//}
//
//+(void)POST:(NSString *)url baseURL:(NSString *)baseUrl params:(NSDictionary *)params
//    success:(ZJResponseSuccess)success fail:(ZJResponseFail)fail{
//
//    AFHTTPSessionManager *manager = [ZJNetworkingManager managerWithBaseURL:baseUrl sessionConfiguration:NO];
//    [manager POST:url parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
//
//    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//
//        id dic = [ZJNetworkingManager responseConfiguration:responseObject];
//
//        success(task,dic);
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        fail(task,error);
//    }];
//}
//
//+(void)uploadWithURL:(NSString *)url params:(NSDictionary *)params fileData:(NSData *)filedata name:(NSString *)name fileName:(NSString *)filename mimeType:(NSString *) mimeType progress:(ZJProgress)progress success:(ZJResponseSuccess)success fail:(ZJResponseFail)fail{
//
//    AFHTTPSessionManager *manager = [ZJNetworkingManager managerWithBaseURL:nil sessionConfiguration:NO];
//
//    [manager POST:url parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
//
//        [formData appendPartWithFileData:filedata name:name fileName:filename mimeType:mimeType];
//
//    } progress:^(NSProgress * _Nonnull uploadProgress) {
//
//        progress(uploadProgress);
//
//    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//
//        id dic = [ZJNetworkingManager responseConfiguration:responseObject];
//        success(task,dic);
//
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        fail(task,error);
//    }];
//}
//
//+(void)uploadWithURL:(NSString *)url
//             baseURL:(NSString *)baseurl
//              params:(NSDictionary *)params
//            fileData:(NSData *)filedata
//                name:(NSString *)name
//            fileName:(NSString *)filename
//            mimeType:(NSString *) mimeType
//            progress:(ZJProgress)progress
//             success:(ZJResponseSuccess)success
//                fail:(ZJResponseFail)fail{
//
//    AFHTTPSessionManager *manager = [ZJNetworkingManager managerWithBaseURL:baseurl sessionConfiguration:YES];
//
//    [manager POST:url parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
//        [formData appendPartWithFileData:filedata name:name fileName:filename mimeType:mimeType];
//    } progress:^(NSProgress * _Nonnull uploadProgress) {
//        progress(uploadProgress);
//    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//
//        id dic = [ZJNetworkingManager responseConfiguration:responseObject];
//
//        success(task,dic);
//
//
//        success(task,responseObject);
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        fail(task,error);
//    }];
//}
//
//+(NSURLSessionDownloadTask *)downloadWithURL:(NSString *)url
//                                 savePathURL:(NSURL *)fileURL
//                                    progress:(ZJProgress )progress
//                                     success:(void (^)(NSURLResponse *, NSURL *))success
//                                        fail:(void (^)(NSError *))fail{
//    AFHTTPSessionManager *manager = [self managerWithBaseURL:nil sessionConfiguration:YES];
//
//    NSURL *urlpath = [NSURL URLWithString:url];
//    NSURLRequest *request = [NSURLRequest requestWithURL:urlpath];
//
//    NSURLSessionDownloadTask *downloadtask = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
//        progress(downloadProgress);
//
//    } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
//
//        return [fileURL URLByAppendingPathComponent:[response suggestedFilename]];
//    } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
//
//        if (error) {
//            fail(error);
//        }else{
//
//            success(response,filePath);
//        }
//    }];
//
//    [downloadtask resume];
//
//    return downloadtask;
//}
//
//#pragma mark - Private
//
//+(AFHTTPSessionManager *)managerWithBaseURL:(NSString *)baseURL  sessionConfiguration:(BOOL)isconfiguration{
//
//    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
//    AFHTTPSessionManager *manager = nil;
//
//    NSURL *url = [NSURL URLWithString:baseURL];
//
//    if (isconfiguration) {
//
//        manager = [[AFHTTPSessionManager alloc] initWithBaseURL:url sessionConfiguration:configuration];
//    }else{
//        manager = [[AFHTTPSessionManager alloc] initWithBaseURL:url];
//    }
//
//    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
//    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//
//    return manager;
//}
//
//+(id)responseConfiguration:(id)responseObject{
//
//    NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
//    string = [string stringByReplacingOccurrencesOfString:@"\n" withString:@""];
//    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
//    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
//    return dic;
//}
//
@end

